<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

$query = "SELECT admin " .
		"FROM users " .
		"WHERE user_id = " . $_SESSION[ 'user_id' ];
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if( isset( $row[ 'admin' ] ) && $row[ 'admin' ] == 1 ) {
?>
<html>
	<head>
		<title>
			Ages of Strife: Game settings
		</title>
		<link type="text/css" rel="stylesheet" href="../global/agesofstrife.css" />
	</head>
	<body>
		<div id="root_container">
<?php
	
	include( "../global/ads.php" );
?>
			<div id="container">
<?php
	include_once( "../global/old_database_connection.php" );
?>
				<div id="main-content">
<?php
    if( isset( $_SESSION[ 'game_settings_status' ] ) ) {
    	print( "<div class=\"blok\">Status: " . $_SESSION[ 'game_settings_status' ] . "</div><br />\r\n" );
    	unset( $_SESSION[ 'game_settings_status' ] );
    }
?>
					<div class="blok">
<?php
	$query = "SELECT * " .
			"FROM game";
	$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$row = mysql_fetch_array( $result, MYSQL_ASSOC );
	$start_time = $row[ 'start_time' ];
	if( $start_time > 0 ) {
		$start_time ++;
		$start_hour = date( 'G', $start_time );
		$start_day = date( 'j', $start_time );
		$start_month = date( 'n', $start_time );
		$start_year = date( 'Y', $start_time );

		$currentStartTime = 'Start time configured to: ' . date( 'j M Y \a\t G', $start_time ) . ' o\'clock CEST<br />';
	}
	else {
		$start_hour = 0;
		$start_day = 0;
		$start_month = 0;
		$start_year = 0;
		$currentStartTime = '';
	}
?>	
						<a href="admin.php">Back</a><br />
						<br />
						<strong>Game settings</strong><br />
						<form method="post" action="save_settings.php">
							<input type="checkbox" name="open_shop" id="open_shop" value="open_shop" <?php print( $row[ 'open_shop' ] == 1 ? ' checked="checked"' : '' ); ?>" /> <label for="open_shop">Shop open</label><br />
							<input type="checkbox" name="game_running" id="game_running" value="game_running" <?php print( $row[ 'game_running' ] == 1 ? ' checked="checked"' : '' ); ?>" /> <label for="game_running">Game running</label><br />
							Start date (in CEST, the hour the first turn update should occur):<br />
							Hour: <input size="3" type="text" name="start_hour" value="<?php print( $start_hour ); ?>" /><br />
							Day: <input size="3" type="text" name="start_day" value="<?php print( $start_day ); ?>" /><br />
							Month: <input size="3" type="text" name="start_month" value="<?php print( $start_month ); ?>" /><br />
							Year: <input size="3" type="text" name="start_year" value="<?php print( $start_year ); ?>" /><br />
							<?php print( $currentStartTime ); ?>
							Round name:<br />
							<input size="80" type="text" name="round_name" value="<?php print( $row[ 'round_name' ] ); ?>" /><br />
							Speed: (Seconds per turn)<br />
							<input size="5" type="text" name="speed" value="<?php print( $row[ 'speed' ] ); ?>" /><br />
							Last turn: <br />
							<input size="8" type="text" name="max_turn" value="<?php print( $row[ 'max_turn' ] ); ?>" /><br />
							Extra turns (after round ends): <br />
							<input size="8" type="text" name="extra_turns" value="<?php print( $row[ 'extra_turns' ] ); ?>" /><br />
							Global orders for independent armies:<br />
							<select name="global_orders">
								<option<?php if( $row[ 'global_orders' ] == 0 ) print( ' selected="selected"' ); ?> value="0">Move South</option>
								<option<?php if( $row[ 'global_orders' ] == 1 ) print( ' selected="selected"' ); ?> value="1">Move East</option>
								<option<?php if( $row[ 'global_orders' ] == 2 ) print( ' selected="selected"' ); ?> value="2">Move North</option>
								<option<?php if( $row[ 'global_orders' ] == 3 ) print( ' selected="selected"' ); ?> value="3">Move West</option>
								<option<?php if( $row[ 'global_orders' ] == 4 ) print( ' selected="selected"' ); ?> value="4">Move to the center</option>
								<option<?php if( $row[ 'global_orders' ] == 5 ) print( ' selected="selected"' ); ?> value="5">Move to random spot</option>
							</select><br />
							Special event started: <br />
							<select name="special_event_started">
								<option<?php if( $row[ 'special_event_started' ] == 0 ) print( ' selected="selected"' ); ?> value="0">No</option>
								<option<?php if( $row[ 'special_event_started' ] == 1 ) print( ' selected="selected"' ); ?> value="1">Yes</option>
							</select><br />
							Turns until inactive: <br />
							<input size="8" type="text" name="turns_inactive" value="<?php print( $row[ 'turns_inactive' ] ); ?>" /><br />
							Turns until remove news: <br />
							<input size="8" type="text" name="remove_news" value="<?php print( $row[ 'remove_news' ] ); ?>" /><br />
							Server message: <br />
							<textarea name="server_message" cols="90" rows="12"><?php print( stripslashes( $row[ 'server_message' ] )  ); ?></textarea><br />
							<br />
							<input type="submit" name="submit" value="submit" /><br />
						</form>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
<?php
}
else {
	$_SESSION[ 'admin' ] = 0;
	header( "Location: ../overview/overview.php" );
}
?>
